package com.ydl.learning.flink.demo.transformations

import com.ydl.learning.flink.demo.Utils
import org.apache.flink.streaming.api.scala._
import org.apache.flink.streaming.api.windowing.time.Time

/**
 * 将Stream根据指定的Key进行分区，是根据key的散列值进行分区的。
 *
 * @author ydl
 * @since 2020/9/22
 */
object KeyByDemo extends Utils {
  def main(args: Array[String]): Unit = {
    val stream = getSocketTextStream(9999)
    stream._2.map((_, 1)).keyBy(_._1).timeWindow(Time.seconds(10)).sum(1).print()
    stream._1.execute("keyBy")
  }

}
